<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>vue的data的watch监听</title>
</head>
<body>
  <div id="app">
    <h2>{{message}}</h2>
    <h2>{{info}}</h2>
    <button @click="changeMessage()">修改message</button>
  </div>
  <script src="../lib/vue.js"></script>
  <script>
    // 使用vue
    const app = Vue.createApp({
      template: ``
      ,
      data: function(){
        return {
          message: "hello watch",
          info: {name: "小米", price: 3000}
        }
      }
      ,methods: {
        changeMessage() {
          this.message = "change message",
          this.info = {name: "华为", price: 3800}
        }
      },
      watch: {
        // 默认两个参数: newValue/oldValue
        message(newValue, oldValue) {
          console.log(" message数据发生了变化: " + "原数据: ", oldValue + "新数据: ", newValue)
        },
        info(newValue, oldValue) {
          // 如果是对象类型,拿到的是代理对象
          console.log("获取代理对象")
          console.log(" message数据发生了变化: " + "原数据: ", oldValue, "新数据: ", newValue)
          // 使用+号,和使用逗号的区别
          console.log(" message数据发生了变化: " + "原数据: " + oldValue + "新数据: " + newValue)
          console.log(newValue.name, oldValue.name)
          // 获取原生对象
          console.log("获取原生对象")
          // 获取所有属性
          console.log({...newValue})
          // 或者使用toRaw获取
          console.log(Vue.toRaw(newValue))
        }
      }
    }
    )
    // 挂载 
    app.mount("#app")
  </script>

</body>
</html>
